package com.flyco.modules.oms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyco.modules.oms.entity.StmJdSendOrder;
import com.flyco.modules.oms.mapper.StmJdSendOrderMapper;
import com.flyco.modules.oms.service.IStmJdSendOrderService;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.tomcat.jni.Local;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Description: 发货单
 * @Author: flyco
 * @Date: 2023-08-09
 * @Version: V1.0
 */
@Service
public class StmJdSendOrderServiceImpl extends ServiceImpl<StmJdSendOrderMapper, StmJdSendOrder> implements IStmJdSendOrderService {

    @Autowired
    private StmJdSendOrderMapper stmJdSendOrderMapper;

    @Override
    public List<StmJdSendOrder> getCompleteByOrderId(String orderId) {

        LambdaQueryWrapper<StmJdSendOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StmJdSendOrder::getSrcTradeNo, orderId).eq(StmJdSendOrder::getStatus, "110");
        return stmJdSendOrderMapper.selectList(wrapper);
    }

    @Override
    public List<StmJdSendOrder> getCancelJdSendOrderList(Integer day) {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String endTime = format.format(new Date());

        Calendar instance = Calendar.getInstance();
        instance.setTime(new Date());
        instance.add(Calendar.DATE, -5);
        String beginTime = format.format(instance.getTime());


        LambdaQueryWrapper<StmJdSendOrder> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StmJdSendOrder::getStatus, "5")
                .between(StmJdSendOrder::getCreateDate, beginTime, endTime);
        return stmJdSendOrderMapper.selectList(wrapper);

    }

}
